@echo OFF
ECHO Usage: %0 [/f] [length]
ECHO.
ECHO   [/f]      include symbols chars
ECHO   [length]  a integer of chars count, default is 64
ECHO.

REM ^要用4个^来转义，%要用2个%来转义，而且要放在EnableDelayedExpansion之前，否则!无法转义
set Str=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`-=[];'\/.,~@#^^^^*()_+{}:"|?><$&%%!

SET count=64
SET pwds=62

IF /I "%1" EQU "/f" (
	SET pwds=94
) ELSE (
	IF "%1" NEQ "" (
		SET count=%1
	)
)
IF "%2" NEQ "" (
	SET count=%2
)

SetLocal EnableDelayedExpansion
for /l %%L in (1 1 %count%) do (
    set /a n = !random! %% %pwds%
    for %%n in (!n!) do set Out=!Out!!Str:~%%n,1!
)
echo !Out!